package com.htfyun.eink.pw.draw.pen.epd.charcoal;


public class ColorUtils {

    public static int alphaFromArgb(int color) {
        return 0xFF & (color >> 24);
    }

    public static int grayscaleToRgb32(int val) {
        int i = val & 0xFF;
        return (i | (i << 8)) | (i << 0x10) | 0xFF000000;
    }

    public static int grayscaleFromRgb32(int i) {
        return (5 * (0xFF & i) + ((i >> 4) & 0xFF0) + 0xB * ((i >> 0x10) & 0xFF)) >> 5;
    }

    public static int clampInGrayscale(int i) {
        int result;

        int v1 = i & ~(i >> 0x1F);
        if (v1 >= 0xFF)
            result = 0xFF;
        else
            result = v1;
        return result;
    }
}
